package servlet;

import util.DBUtils;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;
import java.util.List;

public class EssayDelServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        int uid=Integer.parseInt(request.getParameter("fromuid"));
        int eid=Integer.parseInt(request.getParameter("fromeid"));
        System.out.println("eid:"+eid);
        DBUtils db = new DBUtils();
        db.delete("essay","eid="+eid);
        String[] fields = {"eid","title","create_time","update_time","eclass","content"};
        String condition = "uid="+uid;
        List<String[]> list1 = db.find("essay",fields,condition);
        for (String[] arr : list1) {
            System.out.printf("eid:%s,title:%s,create_time:%s,update_time:%s,eclass:%s,content:%s\n",arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]);
        }
        if(list1.isEmpty()){
            System.out.println("信息加载失败");
        }else {
            request.getSession().setAttribute("essayData",list1);
                       /* request.getSession().setAttribute("status","1");
                        request.getSession().setAttribute("msg","信息加载成功");*/
            RequestDispatcher rd = request.getRequestDispatcher("management.jsp");
            rd.forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
